﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace OpenServe.Net.Library.Extentions {
    public static class Extenders {
        public static byte[] ToBytes(this string s) {
            return ASCIIEncoding.ASCII.GetBytes(s);
        }
        public static string BToString(this byte[] s) {
            return ASCIIEncoding.ASCII.GetString(s).TrimEnd('\0');
        }
        public static string format(this string s, params object[] args) {
            return String.Format(s, args);
        }
        public static object Clone(this object o) {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, o);
            ms.Position = 0;
            var obj = bf.Deserialize(ms);
            ms.Close();
            return obj;
        }
    }
}
